package com.sunday.common.validation;

import com.sunday.common.core.gson.GsonUtils;
import jakarta.validation.constraints.*;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @Description: 验证DTO
 * @Author: zsy
 * @Create: 2022/10/15 17:07
 */
@Data
public class ValidationDTO implements Serializable {

    @NotNull
    @AssertFalse
    private Boolean assertFalse;

    @NotNull
    @AssertTrue
    private Boolean assertTrue;

    @NotBlank
    private String notBlank;

    @NotEmpty
    private String notEmpty;

    @NotEmpty
    private List<String> notEmptyList;

    @NotEmpty
    private Map<String, String> notEmptyMap;

    @DecimalMax("10")
    private BigInteger decimalMax;

    @DecimalMin("5")
    private int decimalMin;

    @NotNull
    @Digits(integer = 2, fraction = 2)
    private BigDecimal digits;

    @NotBlank
    @Email
    private String email;

    @Max(10)
    private Long max;

    @Min(5)
    private long min;

    @Negative
    private int negative;

    @NegativeOrZero
    private int negativeOrZero;

    @Null
    private String isNull;

    @Pattern(regexp = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$", message = "邮箱格式非法")
    private String pattern;

    @Past
    private LocalDateTime past;

    @PastOrPresent
    private LocalDate pastOrPresent;

    @Future
    private LocalDateTime future;

    @FutureOrPresent
    private LocalDate futureOrPresent;

    @Positive
    private double positive;

    @PositiveOrZero
    private float positiveOrZero;

    @NotNull
    @Size(min = 1, max = 2)
    private String sizeString;

    @NotEmpty
    @Size(min = 1, max = 2)
    private List<String> sizeList;

    @Size(min = 1, max = 2)
    private Map<String, String> sizeMap;

    @Size(min = 1, max = 2)
    private Integer[] sizeArray;

    @NotBlank
//    @NotNull
    @Size(min = 1, max = 20)
    private String sizeMax;

    @NotNull
    @Positive
    @Max(10)
    private Integer idSize;

    @NotNull
    @Min(1)
    @Max(Long.MAX_VALUE)
    private Long id;

    @Override
    public String toString() {
        return GsonUtils.DEFAULT.toJson(this);
    }
}
